package com.hx.reporter.controller;

import com.hx.common.annotation.Log;
import com.hx.common.core.controller.BaseController;
import com.hx.common.core.domain.AjaxResult;
import com.hx.common.core.page.TableDataInfo;
import com.hx.common.enums.BusinessType;
import com.hx.common.utils.poi.ExcelUtil;
import com.hx.reporter.domain.Friend;
import com.hx.reporter.service.IFriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 好友Controller
 * 
 * @author ${author}
 * @date 2023-05-28
 */
@RestController
@RequestMapping("/friend")
public class FriendController extends BaseController {
    @Autowired
    private IFriendService friendService;

    /**
     * 查询好友列表
     */
    @PreAuthorize("@ss.hasPermi('reporter:friend:list')")
    @GetMapping("/list")
    public TableDataInfo list(Friend friend)
    {
        startPage();
        List<Friend> list = friendService.selectFriendList(friend);
        return getDataTable(list);
    }

    /**
     * 导出好友列表
     */
    @PreAuthorize("@ss.hasPermi('reporter:friend:export')")
    @Log(title = "好友", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Friend friend)
    {
        List<Friend> list = friendService.selectFriendList(friend);
        ExcelUtil<Friend> util = new ExcelUtil<Friend>(Friend.class);
        util.exportExcel(response, list, "好友数据");
    }


    /**
     * 获取好友详细信息
     */
//    @PreAuthorize("@ss.hasPermi('reporter:friend:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getFriendList(@PathVariable("userId") String userId)
    {
        return success(friendService.selectFriendById(userId));
    }

//    /**
//     * 获取好友详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('reporter:friend:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Integer id)
//    {
//        return success(friendService.selectFriendById(id));
//    }

    /**
     * 新增好友
     */
    @PreAuthorize("@ss.hasPermi('reporter:friend:add')")
    @Log(title = "好友", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Friend friend)
    {
        return toAjax(friendService.insertFriend(friend));
    }

    /**
     * 修改好友
     */
    @PreAuthorize("@ss.hasPermi('reporter:friend:edit')")
    @Log(title = "好友", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Friend friend)
    {
        return toAjax(friendService.updateFriend(friend));
    }

    /**
     * 删除好友
     */
    @PreAuthorize("@ss.hasPermi('reporter:friend:remove')")
    @Log(title = "好友", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(friendService.deleteFriendByIds(ids));
    }
}
